package java101;

import javax.swing.JOptionPane;

public class PrimeFinderBoolean {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		int number = 2;
		boolean isItPrime = false;
		int count = 0;
		
		String userInput = JOptionPane.showInputDialog
		("How many numbers shall we count to? ");
		int input = Integer.parseInt(userInput);
		
		for (number = 2; number <= input; number++) {
			
			isItPrime = isPrime(number);
			
			if (isItPrime == true) {
				System.out.println(number);
				count++;
			}
			
		}
		System.out.println();
		System.out.println("There are " + count + " prime numbers between 2 and " + input + " inclusive.");

	}

	private static boolean isPrime(int number) {
		int divisor = 1;
		int remainder = 0;
		
			
			for (divisor = 2; divisor <= Math.sqrt(number); divisor++) {
				
				remainder = number % divisor;
				
				if (remainder == 0) {
					return false;
				}
				
			}
	
			return true;
	}

}
